import { request } from "@/utils/request";

//获取文章集合
export function getArticlesList() {
    return request({
        method: 'post',
        url: 'article/getArticlesList',
        headers: {
            'token': window.localStorage.token,
        },
    })
}
//根据文章id获取文章
export function getArticleById(id) {

    //将id拼接到url上面
    const encodedId = encodeURIComponent(id);
    const url = `article/getArticleById?id=${encodedId}`;

    return request({
        method: 'post',
        url: url,
        headers: {
            'token': window.localStorage.token,
        }
    })
}

export function addArticle(params) {
    return request({
        method:'post',
        url:'article/addArticle',
        data:params,
        headers: {
            'token': window.localStorage.token,
        }
    })
}

export function getArticleByTitle(params){
    return request({
        method:'get',
        url:'article/search',
        params:params,
        headers: {
            'token': window.localStorage.token,
        }
    })
}

export function getArticleByUserId(){
    return request({
        method:'get',
        url:'article/getUserArticle',
        headers: {
            'token': window.localStorage.token,
        }
    })
}

export function delArticleById(params){
    return request({
        method:'delete',
        url:'article/delArticle',
        params:params,
        headers: {
            'token': window.localStorage.token,
        }
    })
}